package com.hello.controller;

import com.hello.service.ExecutorSchedulerService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * @author : bamboo brother
 * @date : 2017-04-12
 */
@Controller
@RequestMapping("/executor/")
public class ExecutorSchedulerController {

    @Resource
    private ExecutorSchedulerService executorSchedulerService;

    /**
     * 添加任务
     *
     * @return
     */

    @RequestMapping("addExecutor/{taskId}")
    @ResponseBody
    public String addExecutor(@PathVariable String taskId) {
        try {
            executorSchedulerService.addExecutorScheduler(taskId);
        } catch (Exception e) {
            e.printStackTrace();

            return "fail";
        }

        return "ok";
    }

    /**
     * @return
     */
    @RequestMapping("pauseExecutor/{taskId}")
    @ResponseBody
    public String pauseExecutor(@PathVariable String taskId) {
        try {
            executorSchedulerService.pauseTask(taskId);
        } catch (Exception e) {
            e.printStackTrace();
            return "fail";
        }

        return "ok";
    }
}
